import {encodeSearchParams} from "@/common/utils/utils.js";

const PREFIX = '/admin/theme'
import request from '@/request/request.js'

/**
 * 获取主题列表
 * @returns {*}
 */
export const getThemeList = (searchData) => request(`${PREFIX}?${encodeSearchParams(searchData)}`)

/**
 * 获取主题关联的商品
 * @param name
 * @returns {Promise | Promise<unknown> | *}
 */
export const getProducts = (name) => request(`${PREFIX}/products${name ? `?name=${name}` : ""}`)

/**
 * 添加主题
 * @param data 表单数据
 * @returns {*}
 */
export const addTheme = (data) => request(`${PREFIX}`, data, 'post')

/**
 * 获取主题
 * @returns {*}
 * @param id
 */
export const getThemeById = (id) => request(`${PREFIX}/${id}`)

/**
 * 修改主题
 * @param data 表单数据
 * @returns {*}
 */
export const updateTheme = (data) => request(`${PREFIX}`, data, 'put')

/**
 * 删除主题
 * @returns {*}
 * @param id
 */
export const deleteTheme = (id) => request(`${PREFIX}/${id}`, null, 'delete')
